class BodyUnion3 extends Body{
  Body a,b,c;

  BodyUnion3(Body a, Body b, Body c){
    super(a.xc.x,a.xc.y,a.window);  
    this.a = a; this.b = b; this.c = c;
  }


  void display( color C, Window window ){
    a.display(C,window);
    b.display(C,window);
    c.display(C,window);
  }

  void display(){
    a.display();
    b.display();
    c.display();
  }
  
  float distance( float x, float y){ // in cells
    return min(a.distance(x,y),b.distance(x,y),c.distance(x,y));
  }
  int distance( int px, int py){     // in pixels
    return min(a.distance(px,py),b.distance(px,py),c.distance(px,py));
  }

  Body closer(float x, float y){
    if(a.distance(x,y)<b.distance(x,y) && a.distance(x,y)<c.distance(x,y)) return a;
    else if(b.distance(x,y)<a.distance(x,y) && b.distance(x,y)<c.distance(x,y)) return b;
    else return c;
  }
  
  PVector WallNormal(float x, float y){
   Body d = closer(x,y);
   return d.WallNormal(x,y); 
  }
  
  float velocity( int d, float dt, float x, float y ){
    Body e = closer(x,y);
    return e.velocity(d,dt,x,y);
  }

  void update(){a.update();b.update();c.update();unsteady=a.unsteady|b.unsteady|c.unsteady;}
  void mousePressed(){a.mousePressed();b.mousePressed();c.mousePressed();}
  void mouseReleased(){a.mouseReleased();b.mouseReleased();c.mouseReleased();}
}
